package cn.edu.ctbu.myblog.service;

import cn.edu.ctbu.myblog.dao.ArticleDAO;
import cn.edu.ctbu.myblog.domain.ArticleDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ArticleService{

    @Autowired
    ArticleDAO articleDAO;




    public List<ArticleDO> getAll(){
        List<ArticleDO> articleDOS=articleDAO.findAll();
        return articleDOS;
    }

    public List<ArticleDO> getById(int id){
        List<ArticleDO> articleDOS=articleDAO.findById(id);
        return articleDOS;
    }

    public void addArticle(String title,String content,int good,int userId){
        Date nowDate = new Date();
        articleDAO.addArticle(title,content,good,nowDate,userId);
    }

    public List<ArticleDO> getByTitle(String title){
        List<ArticleDO> articleDOS=articleDAO.findByTitle(title);
        return articleDOS;
    }

    public void giveGood(String id){
        String c=id.substring(8);
        int real_id = Integer.parseInt(c);
        articleDAO.giveGood(real_id);
    }

}
